<template>
  <div class="goodsDetail">
    <div>
      <div class="mt20">
        <span class="main_active">条形码：</span>
        <el-input
          v-model="formInfo.UUID"
          class="w400"
          :disabled="true"
          type="number"
        />
      </div>
      <div class="mt20">
        <span class="main_active">射频码：</span>
        <el-input v-model="formInfo.ESLCode" class="w400" :disabled="true" />
      </div>
      <div class="mt20">
        <span class="main_active">绑定基站：</span>
        <el-select v-model="formInfo.BSID" class="w400" placeholder="请选择">
          <el-option
            v-for="item in BaseStockData"
            :key="item.BSID"
            :label="'[' + item.BSID + ']' + item.BSName"
            :value="item.BSID"
          />
        </el-select>
      </div>
      <div class="mt20">
        <span class="main_active">屏幕类型：</span>
        <el-select v-model="formInfo.LCDType" class="w400" placeholder="请选择">
          <el-option
            v-for="item in LCDData"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <div class="mt20">
        <span class="main_active">标签模板：</span>
        <el-select
          v-model="formInfo.ESLTypeID"
          class="w400"
          placeholder="请选择"
        >
          <el-option
            v-for="item in modelData"
            :key="item.ETCode"
            :label="item.ETName"
            :value="item.ETCode"
            @click="changename(item)"
          />
        </el-select>
      </div>
      <div class="mt20 goods">
        <span class="main_active">商品名称：</span>
        <el-input v-model="formInfo.shopename" class="w400" :disabled="true" />
        <el-button
          class="button"
          size="small"
          type="primary"
          @click="ProductsData()"
        >
          查询
        </el-button>
      </div>
      <div class="mt20">
        <span class="main_active">版本号：</span>
        <el-input
          v-model="formInfo.Version"
          class="w400"
          placeholder="版本号"
        />
      </div>
      <div class="mt20">
        <span class="main_active">备注：</span>
        <el-input v-model="formInfo.Remark" class="w400" placeholder="备注" />
      </div>
      <div class="mt20">
        <span class="main_active">状态：</span>
        <el-switch
          v-model="formInfo.Status"
          :active-value="1"
          :inactive-value="0"
        />
      </div>
    </div>
    <el-dialog
      v-model="dialogChiled"
      title="商品列表"
      width="650px"
      @close="closeFn"
    >
      <div style="padding-bottom: 20px">
        <span class="color_494949 ft12 pr5">关键字：</span>
        <el-input
          v-model="searchChild"
          class="w164 mr10"
          placeholder="请输入关键字"
        />
        <el-button class="settingBtn mr10" type="primary" @click="ProductsData">
          查询
        </el-button>
      </div>
      <div>
        <el-table
          border
          :data="productData"
          height="400"
          style="width: 600px"
          @selection-change="handleSelectionChangechiled"
        >
          <el-table-column width="55">
            <template #default="{ row }">
              <el-radio-group v-model="productNo" @change="changeproduct(row)">
                <el-radio :label="row.Code" />
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column label="商品编码" prop="Code" />
          <el-table-column label="商品名称" prop="Name" />
        </el-table>
        <div class="pagination">
          <el-pagination
            background
            :current-page="pageNo"
            :layout="layout"
            :page-size="pageSize"
            :total="total"
            @current-change="handleCurrentchiled"
            @size-change="handleSizechiled"
          />
        </div>
      </div>
      <template #footer>
        <el-button @click="dialogChiled = false">取 消</el-button>
        <el-button type="primary" @click="submitChiled">确认</el-button>
      </template>
    </el-dialog>
  </div>
</template>
<script>
  import { getPageData } from '@/api/tag'
  import { ProductsData } from '@/api/eslstock'
  export default {
    name: 'Detail',
    components: {},
    props: {
      form: {
        type: Object,
        default: () => {
          return {}
        },
      },
      basestockdata: {
        type: Array,
        default: () => {
          return []
        },
      },
      dialoginfo: {
        type: Boolean,
        default: false,
      },
    },
    emits: ['deletedchild'],
    data() {
      return {
        formInfo: this.form,
        BaseStockData: this.basestockdata,
        dialogChiled: false,
        modelData: [],
        productData: [],
        pageNo: 1,
        pageSize: 10,
        total: 0,
        productNo: '',
        searchChild: '',
        selectProduct: {},
        layout: 'total, sizes, prev, pager, next, jumper',
        LCDData: [
          {
            label: '212*104',
            value: '00',
          },
          {
            label: '200*200',
            value: '01',
          },
          {
            label: '296*152',
            value: '02',
          },
          {
            label: '250*122',
            value: '03',
          },
          {
            label: '880*528',
            value: '04',
          },
          {
            label: '300*400',
            value: '05',
          },
          {
            label: '296*128',
            value: '06',
          },
        ],
      }
    },
    watch: {
      form(val) {
        this.formInfo = val
      },
      dialoginfo: {
        handler(val) {
          console.log(val)
          if (val) {
            this.getPageData()
          }
        },
        immediate: true,
      },
    },
    methods: {
      changeproduct(e) {
        this.selectProduct = e
      },
      changename(val) {
        console.log(val)
        this.formInfo.ESLTypeName = val.ETName
      },
      submitChiled() {
        if (this.selectProduct) {
          this.formInfo.shopename = `[${this.selectProduct.Code}]${this.selectProduct.Name}`
          this.formInfo.PCode = this.selectProduct.Code
          this.formInfo.PName = this.selectProduct.Name
          this.dialogChiled = false
        }
      },
      async ProductsData() {
        const params = {
          pageNo: 1,
          pageSize: 20,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            {
              name: 'Name',
              value: this.searchChild,
              displayType: 'like',
            },
          ]),
          export: false,
          value: '',
        }
        const data = await ProductsData(params)
        this.productData = data.data.rows
        this.total = data.data.total
        this.dialogChiled = true
      },
      async getPageData() {
        const params = {
          pageNo: 1,
          pageSize: 20,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            {
              name: 'LCDType',
              value:
                this.formInfo.LCDType === '-1' ? '' : this.formInfo.LCDType,
              displayType: 'like',
            },
          ]),
          export: true,
          value: '',
        }
        const data = await getPageData(params)
        this.modelData = data.data.rows
      },
    },
  }
</script>
<style lang="scss" scoped>
  .goodsDetail {
    height: 350px;
  }
  .flex_align {
    display: flex;
    align-items: center;
  }
  .tableDetail {
    padding: 10px;
    .button-add {
      text-align: end;
      padding: 10px;
    }
  }
  .main_active {
    display: inline-block;
    width: 120px;
    text-align: right;
  }
  .mr20 {
    margin-right: 20px;
  }

  .w400 {
    width: 400px !important;
  }
  .mt20 {
    margin-top: 10px;
  }
  .mr10 {
    margin-right: 10px;
  }
  .w320 {
    width: 320px;
  }
  .goods {
    position: relative;

    .button {
      position: absolute;
      right: 40px;
      top: 4px;
    }
  }
  .w164 {
    width: 164px !important;
  }
  ::v-deep .el-scrollbar__wrap {
    overflow-x: auto;
    height: calc(100% + 20px); //多出来的20px是横向滚动条默认的样式
  }
  ::v-deep .el-scrollbar .el-scrollbar__wrap .el-scrollbar__view {
    white-space: nowrap;
    display: inline-block;
  }
  ::v-deep .el-table--scrollable-x .el-table__body-wrapper {
    overflow-x: hidden;
  }
  ::v-deep input[type='number']::-webkit-inner-spin-button,
  ::v-deep input[type='number']::-webkit-outer-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
  }
  ::v-deep .el-radio__label {
    display: none;
  }
</style>
